#!/bin/bash

cd $(dirname $0)

# Compatibility logic for older Anaconda versions.
if [ "${CONDA_EXE} " == " " ]; then
    CONDA_EXE=$((find /opt/conda/bin/conda || find ~/anaconda3/bin/conda || \
	    find /usr/local/anaconda3/bin/conda || find ~/miniconda3/bin/conda  || \
	    find /root/miniconda/bin/conda || find ~/Anaconda3/Scripts/conda) 2>/dev/null)
fi

if [ "${CONDA_EXE}_" == "_" ]; then
    echo "Please install Anaconda w/ Python 3.7+ first"
    echo "See: https://www.anaconda.com/distribution/"
    exit 1
fi

CONDA_BIN=$(dirname ${CONDA_EXE})
MACOS_ENV=setup/environment.yml
LINUX_ENV=setup/environment-linux.yml
WIN64_ENV=setup/environment-win64.yml
ENV_FILE=$MACOS_ENV

if uname | egrep -qe "Linux"; then
    ENV_FILE=$LINUX_ENV
elif uname | egrep -qe "MINGW64"; then
    ENV_FILE=$WIN64_ENV
fi

if ${CONDA_EXE} env list | egrep -qe "^hummingbot"; then
    ${CONDA_EXE} env update -f $ENV_FILE
else
    ${CONDA_EXE} env create -f $ENV_FILE
fi

source "${CONDA_BIN}/activate" hummingbot

# For some reason, this needs to be installed outside of the environment file,
# or it'll give you the graphviz install error.
pip install objgraph

pre-commit install
